<?php
namespace app\backend\model;
use app\common\RootModel;

class MenuModel extends RootModel
{
    protected $pk = 'id';
    protected $table = 'sys_menu';

    /**
     * 子菜单
     * @return \think\model\relation\HasMany
     */
    public function subMenu()
    {
        // 筛选条件
        $where = ['is_show' => 1, 'app' => 'backend'];
        // 筛选字段
        $fields = ['id', 'parent_id', 'title', 'app', 'controller', 'action', 'icon', 'is_menu'];
        // 筛选结果
        return $this->hasMany(MenuModel::class, 'parent_id', 'id')->where($where)
            ->field($fields)->order(['sort' => 'desc']);
    }
}